package cn.hacynn.nd.service.impl;

import cn.hacynn.nd.common.context.BaseContext;
import cn.hacynn.nd.mapper.OrderMapper;
import cn.hacynn.nd.pojo.dto.OrderDTO;
import cn.hacynn.nd.pojo.entity.Orders;
import cn.hacynn.nd.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author Hacynn
 * @Date 2024/6/5 10:43
 * @Version 1.0
 */
@Service/**/
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderMapper orderMapper;


    /**
     * 添加订单
     * @param orderDTO
     */
    @Override
    public Orders add(OrderDTO orderDTO) {
        //订单表信息
        String goodsName = orderDTO.getGoodsName();
        Double total = orderDTO.getTotal();
        //查询用户信息
        Long userId = BaseContext.getCurrentId();
        //存储订单信息
        Orders orders = Orders.builder()
                .goodsName(goodsName)
                .num(1)
                .total(total)
                .status(0)   // 未支付
                .userId(userId)
                .build();
        orderMapper.insert(orders);
        return orders;
    }
}
